


package com.planesnet.activity5;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
/**
 * Lanza una nueva actividad de Navegación.
 * @author "Luis Planes"
 *
 */
public class Activity5Activity extends Activity {
	public static String TAG = "Activity5Activity";
	Context context;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		context = this.getApplicationContext();

	}

	public void navegar(View v) {

		Intent i = new Intent(
				Intent.ACTION_VIEW,
				Uri.parse("google.navigation:q=Avda. Tarragona, 35 22300 Barbastro, España"));
		startActivity(i);

	}

	public void activarGPS(View v) {

		if (!getGps()) {

			Intent in = new Intent(
					android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
			startActivity(in);
		}

	}

	private boolean getGps() {

		//final String GPS = LocationManager.GPS_PROVIDER;
		// Settings.Secure.setLocationProviderEnabled(this.getApplicationContext().getContentResolver(),
		// GPS, true);

		gps1();
		
		
		return false;
	}

	private void gps1() {
		
		/*
		 * !mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
		 */
		
		
		
		try {
			LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

			Method updateProvidersMethod;
			updateProvidersMethod = locationManager.getClass().getMethod("updateProviders");
			updateProvidersMethod.setAccessible(true);
			updateProvidersMethod.invoke(locationManager);

		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}